package com.duobeiyun.gmstest.work

import android.content.Context
import android.util.Log
import androidx.work.CoroutineWorker
import androidx.work.Data
import androidx.work.Worker
import androidx.work.WorkerParameters
import com.duobeiyun.generamessagesdk.ErrorInfo
import com.duobeiyun.generamessagesdk.ResultCallback
import com.duobeiyun.generamessagesdk.channel.GmsChannelListener
import com.duobeiyun.generamessagesdk.channel.bean.ChannelAttributeOptions
import com.duobeiyun.generamessagesdk.channel.bean.GmsChannelAttribute
import com.duobeiyun.generamessagesdk.channel.bean.GmsChannelMember
import com.duobeiyun.generamessagesdk.connect.bean.GmsMessage
import com.duobeiyun.gmstest.TestInstance
import com.duobeiyun.gmstest.log.LogDebug
import com.duobeiyun.gmstest.log.LogOuter
import com.duobeiyun.gmstest.work.sample.WorkAsyncMode
import kotlinx.coroutines.CancellableContinuation
import kotlinx.coroutines.suspendCancellableCoroutine
import java.util.*
import kotlin.coroutines.resume

/**
 * 测试设置频道属性
 */
class WorkSetChannelAttributes(appContext: Context, workerParams: WorkerParameters) :
        WorkAsyncMode(appContext, workerParams) {

    override fun setNumber() {
        TAG = "WorkSendChannelMessage"
        number = "6"
    }
    override fun realWork(continuation: CancellableContinuation<Result>) {


        var channelId = TestInstance.channelId
        TestInstance.setChannelAttributes(channelId!!, mutableListOf(
                GmsChannelAttribute("color", "red"),
                GmsChannelAttribute("background", "yellow"),
                GmsChannelAttribute("title", "")
        ), ChannelAttributeOptions(true),
                object : ResultCallback<Void> {
                    override fun onSuccess(responseInfo: Void?) {
                        LogOuter.print("number:$number \t result:${true} \t name:SetChannelAttributes ")
                        Log.e("MainActivity", "setChannelAttributes success")
                        continuation.resume(Result.success())

                    }

                    override fun onFailure(errorInfo: ErrorInfo) {
                        LogDebug.logE(errorInfo.toString())
                        LogOuter.print("number:$number \t result:${false} \t name:SetChannelAttributes ")
                        Log.e("MainActivity", "setChannelAttributes failure" + errorInfo.errorMsg)
                        continuation.resume(Result.success())
                    }
                })

    }

}